// pages/cultureCoupons/cultureCouponsHistory/index.js
const common = require('../../../public.js')
Page({

  data: {
    userInfo: '',
    token: '',
    discountCouponList: [],
    adminCouponList: [],
    isLoading: false
  },

  onLoad: function (options) {
    let that = this
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
        }, () => {
          that.getCouponsUsedList()
        })
      }
    })
  },
  getCouponsUsedList() {
    this.setData({
      isLoading: true
    })
    const that = this
    const tempJson = {
      userId: that.data.userInfo.id,
      // userId:110,
      token: that.data.token,
    }
    common.post('/cityDisCoupon/getMyUsedCityDisCouponList', tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
          discountCouponList: res.data.discountCouponList,
          adminCouponList: res.data.adminCouponList
        })
      } else {
        common.showRequestErrMsg(res)
      }
    }, function () {
      that.setData({
        isLoading: false
      })
    })
  }
})